package com.qf;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Enumeration;

/**
 * description: 监听session创建的监听器
 * author: Ken
 * 公众号：Java架构栈
 */
@WebListener
public class SessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
//        System.out.println("监听到session创建了！");
        HttpSession session = httpSessionEvent.getSession();
        Enumeration<String> en = session.getAttributeNames();
        while(en.hasMoreElements()){
            String sessionKey = en.nextElement();
            Object value = session.getAttribute(sessionKey);
            System.out.println(sessionKey + "-" + value);
        }
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {

    }
}
